home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_Tix.idb / usr / freeware / lib / tix4.1 / demos / widget.z / widget
Encoding:
Text File  |  1999-01-26  |  8.7 KB  |  368 lines

  1. #!/bin/sh
  2. # the next line restarts using tixwish \
  3. exec tixwish "$0" "$@"
  4.  
  5. # widget --
  6. #
  7. #     This is a demo program of all the available Tix widgets. If
  8. #    have installed Tix properly, you can execute this program
  9. #    directly:
  10. #
  11. #        % widget
  12. #    Otherwise try the following in csh
  13. #
  14. #        % env TIX_LIBRARY=../library tixwish widget
  15. #
  16. #    Or this in sh
  17. #
  18. #        $ TIX_LIBRARY=../library tixwish widget
  19. #
  20. #
  21. #
  22. #----------------------------------------------------------------------
  23. #
  24. #
  25. #    This file has not been properly documented. It is NOT intended
  26. #    to be used as an introductory demo program about Tix
  27. #    programming. For such demos, please see the files in the
  28. #    demos/samples directory or go to the "Samples" page in the
  29. #    "widget demo"
  30. #
  31. #
  32. # Copyright (c) 1996, Expert Interface Technologies
  33. #
  34. # See the file "license.terms" for information on usage and redistribution
  35. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  36. #
  37.  
  38.  
  39. proc MkMainWindow {w} {
  40.     global demo auto_path demo_dir
  41.  
  42.     if ![info exists demo_dir] {
  43.     # Initialize the auto_path and the bitmap directory. The demo_dir
  44.     # variable would be already set by the test program, if we are
  45.     # running in the self test more
  46.     #
  47.     set script [info script]
  48.     if {$script != {}} {
  49.         set demo_dir [file dirname $script]
  50.     } else {
  51.         set demo_dir [pwd]
  52.     }
  53.  
  54.     set demo_dir [tixFSAbsPath $demo_dir]
  55.     }
  56.  
  57.     lappend auto_path $demo_dir
  58.     tix addbitmapdir [tixFSJoin $demo_dir bitmaps]
  59.  
  60.     toplevel $w
  61.     wm title $w "Tix Widget Demonstration"
  62.     wm geometry $w 830x566+100+100
  63.  
  64.     set demo(balloon) [tixBalloon .demos_balloon]
  65.  
  66.     set frame1 [MkMainMenu     $w]
  67.     set frame2 [MkMainNoteBook $w]
  68.     set frame3 [MkMainStatus   $w]
  69.  
  70.     pack $frame1 -side top    -fill x
  71.     pack $frame3 -side bottom -fill x
  72.     pack $frame2 -side top    -expand yes -fill both -padx 4 -pady 4
  73.  
  74.     $demo(balloon) config -statusbar $demo(statusbar)
  75.     set demo(notebook) $frame2
  76. }
  77.  
  78. proc MkMainMenu {top} {
  79.     global demo usebal
  80.  
  81.     set w [frame $top.f1 -bd 2 -relief raised]
  82.  
  83.     menubutton $w.file -menu $w.file.m -text File -underline 0 \
  84.     -takefocus 0
  85.     menubutton $w.help -menu $w.help.m -text Help -underline 0 \
  86.     -takefocus 0
  87.  
  88.     menu $w.file.m
  89.     $w.file.m add command -label "Open ... " -command FileOpen -underline 1 \
  90.     -accelerator "Ctrl+O"
  91.     $w.file.m add sep
  92.     $w.file.m add command -label "Exit     " -command exit -underline 1 \
  93.     -accelerator "Ctrl+X"
  94.     
  95.     menu $w.help.m 
  96.  
  97.     $w.help.m add checkbutton -under 0  -label "Balloon Help " \
  98.     -variable usebal -onvalue 1 -offvalue 0
  99.  
  100.     tixForm $w.file
  101.     tixForm $w.help -right -0
  102.  
  103.     trace variable usebal w BalloonHelp
  104.  
  105.     set usebal 1
  106.  
  107.     # Accelerator bindings
  108.  
  109.     bind all <Control-x> "exit"
  110.     bind all <Control-o> "FileOpen"
  111.  
  112.     return $w
  113. }
  114.  
  115. # Create the main display area of the widget programm. This area should
  116. # utilize the "tixNoteBook" widget once it is available. But now
  117. # we use the cheap substitute "tixStackWindow"
  118. #
  119. proc MkMainNoteBook {top} {
  120.     global demo
  121.     set hasGL 0
  122.  
  123.     option add *TixNoteBook.tagPadX 6
  124.     option add *TixNoteBook.tagPadY 4
  125.     option add *TixNoteBook.borderWidth 2
  126.     option add *TixNoteBook.font\
  127.     -*-helvetica-bold-o-normal-*-14-*-*-*-*-*-*-*
  128.  
  129.     set w [tixNoteBook $top.f2 -ipadx 5 -ipady 5]
  130.     
  131.  
  132.     $w add wel -createcmd "CreatePage MkWelcome  $w wel" \
  133.     -label "Welcome" \
  134.     -under 0
  135.     $w add cho -createcmd "CreatePage MkChoosers $w cho" \
  136.     -label "Choosers" \
  137.     -under 0
  138.     $w add scr -createcmd "CreatePage MkScroll   $w scr" \
  139.     -label "Scrolled Widgets" \
  140.     -under 0
  141.     $w add mgr -createcmd "CreatePage MkManager  $w mgr" \
  142.     -label "Manager Widgets" \
  143.     -under 0
  144.     $w add dir -createcmd "CreatePage MkDirList  $w dir" \
  145.     -label "Directory List" \
  146.     -under 0
  147.     $w add exp -createcmd "CreatePage MkSample   $w exp" \
  148.     -label "Run Sample Programs" \
  149.     -under 0
  150.  
  151.     if {$hasGL} {
  152.     $w add glw -createcmd "MkGL $w glw" -tag "GL Widgets"
  153.     }
  154.  
  155.     return $w
  156. }
  157.  
  158. proc CreatePage {command w name} {
  159.     tixBusy $w on
  160.     set id [after 10000 tixBusy $w off]
  161.     $command $w $name
  162.     after cancel $id
  163.     after 0 tixBusy $w off
  164. }
  165.  
  166. proc MkMainStatus {top} {
  167.     global demo
  168.  
  169.     set w [frame $top.f3 -relief raised -bd 1]
  170.     set demo(statusbar) \
  171.     [label $w.status -font -*-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*\
  172.      -relief sunken -bd 1]
  173.  
  174.     tixForm $demo(statusbar) -padx 3 -pady 3 -left 0 -right %70
  175.  
  176.     return $w
  177. }
  178.  
  179. proc MkWelcome {nb page} {
  180.     set w [$nb subwidget $page]
  181.  
  182.     set bar  [MkWelcomeBar  $w]
  183.     set text [MkWelcomeText $w]
  184.  
  185.     pack $bar  -side top -fill x -padx 2 -pady 2
  186.     pack $text -side top -fill both -expand yes
  187. }
  188.  
  189. proc MkWelcomeBar {top} {
  190.     global demo
  191.  
  192.     set w [frame $top.bar -bd 2 -relief groove]
  193.  
  194.     # Create and configure comboBox 1
  195.     #
  196.     tixComboBox $w.cbx1 -command "MainTextFont $top" \
  197.     -options {
  198.         entry.width    15
  199.         listbox.height 3
  200.     }
  201.     tixComboBox $w.cbx2 -command "MainTextFont $top" \
  202.     -options {
  203.         entry.width 4
  204.         listbox.height 3
  205.     }
  206.     set demo(welfont) $w.cbx1
  207.     set demo(welsize) $w.cbx2
  208.     
  209.     $w.cbx1 insert end "Courier"
  210.     $w.cbx1 insert end "Helvetica"
  211.     $w.cbx1 insert end "Lucida"
  212.     $w.cbx1 insert end "Times Roman"
  213.  
  214.     $w.cbx2 insert end 8
  215.     $w.cbx2 insert end 10
  216.     $w.cbx2 insert end 12
  217.     $w.cbx2 insert end 14
  218.     $w.cbx2 insert end 18
  219.  
  220.     $w.cbx1 pick 1
  221.     $w.cbx2 pick 3
  222.  
  223.     # Pack the comboboxes together
  224.     #
  225.     pack $w.cbx1 $w.cbx2 -side left -padx 4 -pady 4
  226.  
  227.     $demo(balloon) bind $w.cbx1\
  228.     -msg "Choose\na font" -statusmsg "Choose a font for this page"
  229.     $demo(balloon) bind $w.cbx2\
  230.     -msg "Point size" -statusmsg "Choose the font size for this page"
  231.  
  232.  
  233.     tixDoWhenIdle MainTextFont $top
  234.     return $w
  235. }
  236.  
  237. proc MkWelcomeText {top} {
  238.     global demo tix_version
  239.  
  240.     set w [tixScrolledWindow $top.f3 -scrollbar auto]
  241.     set win [$w subwidget window]
  242.  
  243.     label $win.title -font -*-times-bold-r-normal-*-18-*-*-*-*-*-*-*\
  244.     -bd 0 -width 30 -anchor n\
  245.     -text "Welcome to TIX version $tix_version"
  246.  
  247.     message $win.msg -font -*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*\
  248.     -bd 0 -width 400 -anchor n\
  249.     -text "\
  250. Tix $tix_version is a library of mega-widgets based on TK. This program \
  251. demonstrates the widgets in the Tix widget. You can choose the pages \
  252. in this window to look at the corresponding widgets. \
  253. To quit this program, choose the \"File | Exit\" command."
  254.  
  255.  
  256.     pack $win.title -expand yes -fill both -padx 10 -pady 10
  257.     pack $win.msg -expand yes -fill both -padx 10 -pady 10
  258.     set demo(welmsg) $win.msg 
  259.     return $w
  260. }
  261.  
  262. proc MainTextFont {w args} {
  263.     global demo
  264.  
  265.     if {![info exists demo(welmsg)]} {
  266.     return
  267.     }
  268.  
  269.     set font  [$demo(welfont) cget -value]
  270.     set point [$demo(welsize) cget -value]
  271.  
  272.     case $font {
  273.     "Courier" {
  274.         set f courier
  275.     }
  276.     "Helvetica" {
  277.         set f helvetica
  278.     }
  279.     "Lucida" {
  280.         set f lucida
  281.     }
  282.     default {
  283.         set f times
  284.     }
  285.     }
  286.  
  287.     set xfont [format "-*-%s-bold-r-normal-*-%s-*-*-*-*-*-*-*" $f $point]
  288.     if [catch {$demo(welmsg) config -font $xfont} err] {
  289.     puts \a$err
  290.     }
  291. }
  292.  
  293. proc FileOpen {} {
  294.     global demo demo_dir
  295.     set filedlg [tix filedialog tixExFileSelectDialog]
  296.     if {![info exists demo(filedialog)]} {
  297.     $filedlg subwidget fsbox config -pattern *.tcl
  298.     $filedlg subwidget fsbox config -directory $demo_dir/samples
  299.     $filedlg config -command FileOpen:Doit
  300.     set demo(filedialog) $filedlg
  301.     }
  302.     $filedlg config -title "Open Tix Sample Programs"
  303.     $filedlg popup
  304.     tixPushGrab $filedlg
  305. }
  306.  
  307. proc FileOpen:Doit {filename} {
  308.     global demo
  309.   
  310.     LoadFile $filename
  311.     tixPopGrab
  312.     $demo(filedialog) popdown
  313. }
  314.  
  315. #----------------------------------------------------------------------
  316. # Balloon Help
  317. #----------------------------------------------------------------------
  318. proc BalloonHelp {args} {
  319.     global demo usebal
  320.  
  321.     if {$usebal} {
  322.     $demo(balloon) config -state "both"
  323.     } else {
  324.     $demo(balloon) config -state "none"
  325.     }
  326. }
  327.  
  328. #----------------------------------------------------------------------
  329. # Self-testing
  330. #
  331. #    The following code are called by the Tix test suite. It opens
  332. #    every page in the demo program.
  333. #----------------------------------------------------------------------
  334. proc Widget:SelfTest {} {
  335.     global demo testConfig
  336.  
  337.     if ![info exists testConfig] {
  338.     return
  339.     }
  340.  
  341.     MkMainWindow .widget
  342.  
  343.     update
  344.     foreach p [$demo(notebook) pages] {
  345.     $demo(notebook) raise $p
  346.     update
  347.     }
  348.  
  349.     destroy .widget
  350. }
  351.  
  352.  
  353. #----------------------------------------------------------------------
  354. # Start!
  355. #----------------------------------------------------------------------
  356. if ![info exists testConfig] {
  357.     #
  358.     # If the testConfig variable exists, we are driven by the regression
  359.     # test. In that case, don't open the main window. The test program will
  360.     # call Widget:SelfTest
  361.     #
  362.     wm withdraw .
  363.     MkMainWindow .widget
  364.     bind .widget <Destroy> "exit"
  365. }
  366.  
  367.